package com.msmall.community.wish.dao.hibernate;

import java.util.List;

import com.msmall.base.dao.hibernate.BaseDaoHibernate;
import com.msmall.community.wish.dao.WishDao;
import com.msmall.community.wish.model.WishType;

@SuppressWarnings("unchecked")
public class WishDaoHibernate extends BaseDaoHibernate implements WishDao{
	/**
	 * 通过类型名称查找类型
	 */
	public WishType loadByName(String name) throws Exception{
		String queryString = "from WishType where name=?";
		List list = getHibernateTemplate().find(queryString, new Object[]{name});
		if(list != null && list.size() > 0){
			return (WishType) list.get(0);
		}
		return null;
	}
	
	/**
	 * 获得心愿类型<br/>
	 * enabled = ConstantDB.AVALIABLE / ConstantDB.UNAVALIBLE<br/>
	 * enabled == null 取全部
	 */
	public List<WishType> getWishTypes(Short enabled) throws Exception{
		String queryString = "from WishType";
		if(enabled == null){
			queryString += " order by typeid ASC";
			return getHibernateTemplate().find(queryString);
		}else{
			queryString += " where enabled=? order by typeid ASC";
			return getHibernateTemplate().find(queryString, new Object[]{enabled});
		}
	}
}
